// 获取页面id
let url=decodeURI(window.location.href);
console.log(url);
var cs=url.split("?")[1].split("=");

var csKey=cs[0].toLowerCase();
var csvalue=+cs[1];
let o ={[csKey]:csvalue};
console.log(csvalue);

// nav a标签设置
/* $(".one").click(function(){
                    console.log($(this));
$(this).href=`../html/detail.html?categoryid=${csvalue}`;
}) */

// 输入网址进行渲染
var ran=document.querySelector("#ran")
const xhr1=new XMLHttpRequest();
xhr1.open("get","http://chst.vip:1234/api/getproduct?productid="+csvalue,false)
xhr1.onload=function(){
var lis='';
if(xhr1.status===200){
let res1=JSON.parse(xhr1.responseText)
console.log(res1.result[0]);

                    lis=`
                    <div class="info">
                    <div class="pic">
                    ${res1.result[0].productImg}
                    </div>
                    <div class="title">
                    ${res1.result[0].productName}
                    </div>
                    <div class="count">
                    <div class="row">
                                        <div class="col-1">
                                        <span>当前最低</span> 
                                        <span>￥6000</span>           
                                        </div>
                                        <div class="col-1">
                                        <span>优选评论</span> 
                                        <span>8266条</span>           
                                        </div>                   
                    </div>
                    </div>
                    ${res1.result[0].bjShop}
`;      
ran.innerHTML=lis;
}}
xhr1.send();

var comment=document.querySelector(".comment")
const xhr2=new XMLHttpRequest();
xhr2.open("get","http://chst.vip:1234/api/getproductcom?productid="+csvalue,false)
xhr2.onload=function(){
var lis2='';
if(xhr2.status===200){
let res2=JSON.parse(xhr2.responseText);
console.log(res2.result);
res2.result.forEach(element => {
console.log(element);  
lis2+=`        
                  
                   <div class="commentcont">
                    <div class="top">
                    <span>${element.comName}</span>
                    <span>${element.comTime}</span>
                    </div>
                    <div class="mid">
                      ${element.comContent}
                    </div>
                    <div class="bot">
                    <span>${element.comFrom}</span>
                   </div>
                   </div>
                      
                   
                    
`
});
}
comment.innerHTML=lis2;
}
xhr2.send();
